package org.jeecg.modules.mobile.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.mobile.entity.MobileUserConfig;
import org.jeecg.modules.mobile.entity.vo.MobileUserConfigAddVO;
import org.jeecg.modules.mobile.service.IMobileUserConfigService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 移动端用户配置信息
 * @Author: jeecg-boot
 * @Date:   2023-09-14
 * @Version: V1.0
 */
@Api(tags="移动端用户配置信息")
@RestController
@RequestMapping("/mobile/userConfig")
@Slf4j
public class MobileUserConfigController extends JeecgController<MobileUserConfig, IMobileUserConfigService> {
	@Autowired
	private IMobileUserConfigService mobileUserConfigService;
	
	/**
	 *   保存
	 *
	 * @param vo
	 * @return
	 */
	@AutoLog(value = "移动端用户配置信息-保存")
	@ApiOperation(value="移动端用户配置信息-保存", notes="移动端用户配置信息-保存")
	@PostMapping(value = "/save")
	public Result<String> add(@RequestBody MobileUserConfigAddVO vo) {
		mobileUserConfigService.saveConfig(vo);
		return Result.OK("保存成功！");
	}
	
	/**
	 * 查询用户配置
	 *
	 * @param userId
	 * @return
	 */
	@ApiOperation(value="移动端用户配置信息-查询用户配置", notes="移动端用户配置信息-查询用户配置")
	@GetMapping(value = "/queryByUserId")
	public Result<MobileUserConfig> queryById(@RequestParam("userId") String userId) {
		MobileUserConfig one = mobileUserConfigService.getOne(new LambdaQueryWrapper<MobileUserConfig>()
				.eq(MobileUserConfig::getUserId, userId)
				.last("limit 1"));
		if(one == null) {
			one = new MobileUserConfig();
		}
		return Result.OK(one);
	}

}
